package com.speech.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.speech.R;
import com.speech.item.CoinDetailListViewItem;

import java.util.List;

public class CoinDetailListViewAdapter extends BaseAdapter {

    private List<CoinDetailListViewItem> mLstItem;
    private Context mContext;

    public CoinDetailListViewAdapter(List<CoinDetailListViewItem> lstItem,Context context) {
        mLstItem = lstItem;
        mContext = context;
    }

    @Override
    public int getCount() {
        return mLstItem.size();
    }

    @Override
    public Object getItem(int position) {
        return mLstItem.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView==null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.item_coin_detail, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_title = convertView.findViewById(R.id.tv_item_coinDetail_title);
            viewHolder.tv_coin_num = convertView.findViewById(R.id.tv_item_coinDetail_number);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_title.setText(mLstItem.get(position).strTitle);
        viewHolder.tv_coin_num.setText(mLstItem.get(position).strCoinNum);

        return convertView;
    }

    class ViewHolder{
        TextView tv_title;
        TextView tv_coin_num;
    }
}
